package me.zhengjie.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.domain.vo.FlowConfigQueryCriteria;
import me.zhengjie.service.FlowConfigToolService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 18485
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "工具:流程")
@RequestMapping("/api/logicFlow")
public class FlowController {

    private final FlowConfigToolService flowConfigToolService;

    private static final String ENTITY_NAME = "flow";

    // 工作流部署（添加、编辑）
    @Log("工作流部署")
    @ApiOperation("工作流部署: 工具")
    @PostMapping("/addFlow")
    public ResponseEntity<Object> addFlow(@RequestBody Map<String,String> map){
        flowConfigToolService.addFlow(map);
        return new ResponseEntity<>(HttpStatus.CREATED);

    }

    // 工作流返回
    @Log("工作流返回")
    @ApiOperation("工作流返回: 工具")
    @PostMapping("/infoFlow")
    public ResponseEntity<Object> infoFlow(@RequestBody Map<String,String> map) {
        return new ResponseEntity<>(flowConfigToolService.infoFlow(map),HttpStatus.OK);
    }

    // 工作流删除
    @Log("工作流删除")
    @ApiOperation("工作流删除: 工具")
    @PostMapping("/deleteFlow")
    public ResponseEntity<Object> deleteFlow(@RequestBody Map<String,String> map) {
        flowConfigToolService.deleteFlow(map);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    // 工作流查询
    @Log("工作流查询")
    @ApiOperation("工作流查询: 工具")
    @PostMapping("/getDeployList")
    public ResponseEntity<Object> getDeployList(FlowConfigQueryCriteria criteria) {
        flowConfigToolService.getDeployList(criteria);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    // 流程实例
    @Log("流程实例")
    @ApiOperation("流程实例: 工具")
    @PostMapping("/deploymentRun")
    public ResponseEntity<Object> deploymentRun(@RequestBody Map<String,String> map) {
        flowConfigToolService.deploymentRun(map.get("userId"), map.get("key"));
        return new ResponseEntity<>(HttpStatus.OK);
    }

    // 流程查询
    @Log("流程查询")
    @ApiOperation("流程查询: 工具")
    @PostMapping("/infoTask")
    public ResponseEntity<Object> infoTask(@RequestBody Map<String,String> map) {
        flowConfigToolService.infoTask(map.get("userId"));
        return new ResponseEntity<>(HttpStatus.OK);
    }

    // 流程执行
    @Log("流程执行")
    @ApiOperation("流程执行: 工具")
    @PostMapping("/makeTask")
    public  ResponseEntity<Object> makeTask(@RequestBody Map<String,String> map) {
        flowConfigToolService.makeTask(map.get("userId"));
        return new ResponseEntity<>(HttpStatus.OK);
    }

    // 流程历史
    @Log("流程历史")
    @ApiOperation("流程历史: 工具")
    @PostMapping("/taskHistory")
    public ResponseEntity<Object> taskHistory() {
        flowConfigToolService.taskHistory();
        return new ResponseEntity<>(HttpStatus.OK) ;
    }

    // 测试
//    @CrossOrigin
//    @PostMapping("/test")
//    public Result test(@RequestBody AskForLeaveVO test) {
//        return flowService.test(test);
//    }


}